﻿<template>
	<div class="stall-container">
		<el-dialog v-model="isShowDialog" :width="800" draggable="" :close-on-click-modal="false">
			<template #header>
				<div style="color: #fff">
					<span>{{ props.title }}</span>
				</div>
			</template>
			<el-form :model="ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
				<el-row :gutter="35">
					<el-form-item v-show="false">
						<el-input v-model="ruleForm.id" />
					</el-form-item>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="车位号" prop="carNo">
							<el-input v-model="ruleForm.carNo" placeholder="请输入车位号" maxlength="32" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="小区" prop="roomId">
							<el-select clearable filterable v-model="ruleForm.roomId" placeholder="请选择房屋Id">
								<el-option v-for="(item,index) in communityRoomIdDropdownList" :key="index" :value="item.value" :label="item.label" />
								
							</el-select>
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="车位类型" prop="carType">
							<el-select clearable v-model="ruleForm.carType" placeholder="请选择车位类型">
								<!-- <el-option v-for="(item,index) in dl('GenderEnum')"  :key="index" :value="Number(item.code)" :label="`[${item.code}] ${item.value}`"></el-option> -->
								<el-option :value="1" label="地面"/>
								<el-option :value="2" label="地库"/>
							</el-select>
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="运营模式" prop="operation">
							<el-select clearable v-model="ruleForm.operation" placeholder="请选择运营模式">
								<!-- <el-option v-for="(item,index) in dl('GenderEnum')"  :key="index" :value="Number(item.code)" :label="`[${item.code}] ${item.value}`"></el-option> -->
								<el-option :value="1" label="销售">销售</el-option>
								<el-option :value="2" label="租赁">租赁</el-option>
							</el-select>
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="运营状态" prop="operationState">
							<el-select clearable v-model="ruleForm.operationState" placeholder="请选择运营状态">
								<!-- <el-option v-for="(item,index) in dl('StatusEnum')" :key="index" :value="Number(item.value)" :label="`${item.name} (${item.code}) [${item.value}]`"></el-option> -->
								<el-option :value="1" label="正常">正常</el-option>
								<el-option :value="2" label="待租">待租</el-option>
								<el-option :value="3" label="维修中">维修中</el-option>
								<el-option :value="4" label="代售">待售</el-option>
								<el-option :value="5" label="停用">停用</el-option>
							</el-select>
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="费用" prop="stopCarMoney">
							<el-input v-model="ruleForm.stopCarMoney" placeholder="请输入费用" maxlength="10" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="车位状态" prop="carState">
							<el-select clearable v-model="ruleForm.carState" placeholder="请选择车位状态">
								<!-- <el-option v-for="(item,index) in dl('GenderEnum')"  :key="index" :value="Number(item.code)" :label="`[${item.code}] ${item.value}`"></el-option> -->
								<el-option :value="1" label="正常">正常</el-option>
								<el-option :value="2" label="异常">异常</el-option>
							</el-select>
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="用户名" prop="peopleId">
							<el-select clearable filterable v-model="ruleForm.peopleId" placeholder="请选择人员管理Id">
								<el-option v-for="(item,index) in occupantAuditPeopleIdDropdownList" :key="index" :value="item.value" :label="item.label" />
								
							</el-select>
							
						</el-form-item>
						
					</el-col>
					<!--<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						 <el-form-item label="用户名" prop="occupantName" v-if="asd=='编辑车位表'">
							<el-input v-model="ruleForm.occupantName" placeholder="请输入用户名" maxlength="32" show-word-limit clearable />
						</el-form-item> 
						
					</el-col>-->
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="用户电话" prop="occupantPhone" v-if="asd=='编辑车位表'">
							<el-input v-model="ruleForm.occupantPhone" placeholder="请输入用户电话" maxlength="32" show-word-limit clearable />
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" >
						<el-form-item label="有效期限"  prop="occupantExpirationTime" v-if="asd=='编辑车位表'">
							 <el-input v-model="ruleForm.occupantExpirationTime" placeholder="请输入有效期限" maxlength="32" show-word-limit clearable /> 
						
						</el-form-item>
						
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel">取 消</el-button>
					<el-button type="primary" @click="submit">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>
<style lang="scss" scoped>
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>
<script lang="ts" setup>
	import { ref,onMounted } from "vue";
	import { ElMessage } from "element-plus";
	import type { FormRules } from "element-plus";
	import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
	import { getDictLabelByVal as dv } from '/@/utils/dict-utils';
  	import { formatDate } from '/@/utils/formatTime';
	import { addStall, updateStall, detailStall } from "/@/api/parking/stall";
	import { getCommunityRoomIdDropdown } from '/@/api/parking/stall';
	import { getOccupantAuditPeopleIdDropdown } from '/@/api/parking/stall';
	import { getAPI } from '/@/utils/axios-utils';
	import { SysEnumApi } from '/@/api-services/api';
	import {ElMessageBox} from 'element-plus'

	//父级传递来的参数
	var props = defineProps({
		title: {
		type: String,
		default: "",
	},
	});
	//父级传递来的函数，用于回调
	const emit = defineEmits(["reloadTable"]);
	const ruleFormRef = ref();
	const isShowDialog = ref(false);
	const ruleForm = ref<any>({});
	//自行添加其他规则
	const rules = ref<FormRules>({
	});
const asd=ref('')
	//页面加载时
	onMounted(() => {
		asd.value=localStorage.getItem("editStallTitle")
	});


	// 打开弹窗
	const openDialog = async (row: any) => {
		console.log(row);
		// ruleForm.value = JSON.parse(JSON.stringify(row));
		// 改用detail获取最新数据来编辑
		let rowData = JSON.parse(JSON.stringify(row));
		if (rowData.id)
		
		ruleForm.value = (await detailStall(rowData.id)).data.result;
		
		else
			ruleForm.value = rowData;
		isShowDialog.value = true;
		console.log(ruleForm.value);
	};


	// 关闭弹窗
	const closeDialog = () => {
		emit("reloadTable");
		isShowDialog.value = false;
	};

	// 取消
	const cancel = () => {
		isShowDialog.value = false;
	};

	// 提交
	const submit = async () => {
		ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
			if (isValid) {
				let values = ruleForm.value;
				if (ruleForm.value.id == undefined || ruleForm.value.id == null || ruleForm.value.id == "" || ruleForm.value.id == 0) {
					await addStall(values);
				} else {
					await updateStall(values);
				}
				closeDialog();
			} else {
				ElMessage({
					message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
					type: "error",
				});
			}
		});
	};

	const communityRoomIdDropdownList = ref<any>([]); 
	const getCommunityRoomIdDropdownList = async () => {
		let list = await getCommunityRoomIdDropdown();
		communityRoomIdDropdownList.value = list.data.result ?? [];
	};
	getCommunityRoomIdDropdownList();
	
	const occupantAuditPeopleIdDropdownList = ref<any>([]); 
	const getOccupantAuditPeopleIdDropdownList = async () => {
		let list = await getOccupantAuditPeopleIdDropdown();
		occupantAuditPeopleIdDropdownList.value = list.data.result ?? [];
	};
	getOccupantAuditPeopleIdDropdownList();
	





	//将属性或者函数暴露给父组件
	defineExpose({ openDialog });
</script>




